﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZhengShouZBBBControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox txt_nf;
        CustomGridView GridList;
        Button btninsert, btnsearch;

        public string userid = string.Empty;
        
        protected override void OnLoad(EventArgs e)
        {
            //if (HttpContext.Current.Session["UserID"] == null)
            //{
            //    Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            //}
            //else
            //{
            //    userid = HttpContext.Current.Session["UserID"].ToString();
            //}
            InitControl();
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                Bind();
            }
            if (Page.Request["Id"]!=null)
            {
                DelZBB();
            }
        }

       

        protected void InitControl()
        {
            txt_nf = (TextBox)FindControl("txt_nf");
            GridList = (CustomGridView)FindControl("GridList");
            GridList.OnLoadData += new EventHandler(GridList_OnLoadData);
            btninsert = (Button)FindControl("btninsert");
            btninsert.Click += new EventHandler(btninsert_Click);
            btnsearch = (Button)FindControl("btnsearch");
            btnsearch.Click += new EventHandler(btnsearch_Click);
        }

     
     
        protected void Bind()
        {
            string sqlwhere = string.Empty;
            if (!string.IsNullOrEmpty(txt_nf.Text.Trim()))
            {
                sqlwhere += " and Name like '%" + txt_nf.Text.Trim() + "%'";
            }
            string sql = "Select * From zs_zrb  where 1=1 "+sqlwhere;
            DataTable dt = _EluZSDataProvider.GetTable(sql);
                GridList.DataSource = dt;
                GridList.RecordCount = dt.Rows.Count;
                GridList.DataBind();
        }

        private void DelZBB()
        {
            string sql = @"delete from zs_zrb where id = '"+Page.Request["id"]+"' ";
            _EluZSDataProvider.RunSqlNon(sql);
            string sql1 = @"delete from zs_zrb_person where zid = '" + Page.Request["id"] + "' ";
            _EluZSDataProvider.RunSqlNon(sql1);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('删除成功！');<script>");
            Bind();
        }

        protected void GridList_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }


       protected void btnsearch_Click(object sender, EventArgs e)
        {
            Bind();
        }

       protected void btninsert_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect("ZhengShouZBBPerson.aspx"); 
        }

    }
}


